<?php

namespace Home\Controller;
use Think\Controller;
use Home\Controller\BaseController;


class FileActionController extends BaseController {

	
	function index(){
		
		$this->display();
	}

	function quickManage(){
		$filelist = M('filelist')->field('*,FROM_UNIXTIME(addtime) as datetime')->where('user_id=%d',$this->user_id)->select();
		$this->assign('list', json_encode($filelist));
		$this->display();
	}
	function delAction($id){

		$filepath =   M('filelist')->field('filepath')->where('id=%d',$id)->find()['filepath'];
		$unlink_res = unlink($filepath);
		if($unlink_res){
			$delres = M('filelist')->where('id=%d',$id)->delete();
			if($delres != false){
				$res = 0;
			}else{
				$res = 1;
			}
		}else{
			$res = 1;
		}

		return $e;
	}
	function del(){
		$post = getPost();
		$id = $post;
		$res = $this->delAction($id);

		if($res == 0){
			$e['code'] = 0;
			$e['msg'] = '删除成功';

		}else{
			$e['code'] = 1;
			$e['msg'] = '删除失败';
		}
		postReturn($e);
		
	}

	function delMore(){
		$post = getPost();

		$id_list = $post;
		$res = 0;
		foreach ($id_list as $key => $value) {

			$res +=$this->delAction($value);
		}

		if($res == 0){
			$e['code'] = 0;
			$e['msg'] = '删除成功';
		}else{
			$e['code'] = 1;
			$e['msg'] = '有'.$res.'个文件删除失败';
		}

		postReturn($e);
	}
	  

}